package com.ywm.staService.schedule;

import com.ywm.staService.service.StatisticsDailyService;
import com.ywm.staService.utils.DateUtil;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 定时任务类
 */
@Component
public class ScheduleTask {
    private StatisticsDailyService service;
//    int i=0;
//    //0/5 * * * * ? 表示每隔5s执行一次
//    @Scheduled(cron = "0/5 * * * * ?")
//    public void task1(){
//        System.out.println("=================="+(i++)+"================");
//    }

    //在每天凌晨一点，把前一天数据进行查询添加
    @Scheduled(cron = "0 0 1 * * ?")
    public void task2(){
        try {
            service.registerCount(DateUtil.formatDate(DateUtil.addDays(new Date(),-1)));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

